# !/usr/bin/env python
# coding: utf-8
# @Time    : 2017/11/1 14:49
# @Author  : 6imensiva
# @Site    : https://gitee.com/dimensiva/app_server.git
# @File    : my_response.py
# @Software: PyCharm
# @Version: 3.5.4

import json
from . import code


def fail(error_msg, error_code=code.c_sys_exception):
	return json.dumps({'code': error_code, 'msg': error_msg, 'data': None})


def success(data=None, msg=code.m_success):
	"""
	data的数据类型如果是json-string，先自己转成python dict

	:param data:
	:param msg:
	:return:
	"""
	return json.dumps({'code': code.c_success, 'msg': msg, 'data': data})


if __name__ == '__main__':
	a = ['aaa', 'bbb', 'ccc']
	c = success(a)
	print(type(c))
	b = json.loads(c, encoding='utf-8')
	print(type(b['code']))